home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-1.iso / Files / Internet / Misc / Uupc 3.1 sources.sit / uupc 3.1 sources Folder / (uupc π) / tcpglue.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-26  |  2.0 KB  |  78 lines  |  [TEXT/KAHL]

  1. #include "dcp.h"
  2.  
  3. #include    "MacTCPCommonTypes.h"
  4. #include    "AddressXlation.h"
  5. #include    "GetMyIPAddr.h"
  6. #include    "TCPPB.h"
  7. #include    "UDPPB.h"
  8.  
  9. #include    "TCP.h"
  10.  
  11. static    TCPNotifyProc    asrProc            = nil;
  12. static    TCPiopb            pb;
  13. static    StreamPtr        stream;
  14. static    char            streamBuf[4096];
  15. static    long            streamBufLen    = sizeof(streamBuf);
  16. static    Ptr                streamBufPtr;
  17. static    ip_addr            localIP            = cAnyIP;
  18. static    ip_port            localPort        = cAnyPort;
  19. static    ip_addr            remoteIP        = cAnyIP;
  20. static    ip_port            remotePort        = 540; /* uucp listener daemon */
  21. static    WDS(1)            wds;
  22.  
  23. pascal void    StrToAddrResultProc(aHostInfo, userdata)    /* utility routine for StrToAddr */
  24.     struct hostInfo    *aHostInfo;
  25.     Ptr                userdata;
  26. {
  27.     /* simply watch the aHostInfo.rtnCode! */
  28. }
  29.  
  30. OSErr TCPDotAddress(char *dotAddress, ip_addr *ipAddress) {
  31.     auto    OSErr                osErr;
  32.     auto    struct hostInfo        aHostInfo;            /* a data structure for the DNR function */
  33.  
  34.     osErr = OpenResolver((char *) 0);
  35.     if (osErr) {
  36.         return osErr;
  37.     }
  38.     
  39.     /* ask the DNR function to get the IP address */
  40.     StrToAddr(dotAddress, &aHostInfo, (ResultProcPtr) StrToAddrResultProc, (Ptr) 0);
  41.     
  42.     /* wait for the address information or some error other than cacheFault to occur */
  43.     while (cacheFault == aHostInfo.rtnCode)
  44.         ;
  45.     
  46.     osErr = CloseResolver();
  47.     if (osErr) {
  48.         return osErr;
  49.     }
  50.  
  51.     /* if it was an error there isn't much more we can do here but let the caller know */
  52.     if (noErr != aHostInfo.rtnCode) {
  53.         osErr = aHostInfo.rtnCode;
  54.         return osErr;
  55.     }
  56.     
  57.     /* use the first IP address for this host */
  58.     *ipAddress = aHostInfo.addr[0];
  59.                 
  60.     return osErr;
  61. }
  62.  
  63. OSErr open_tcp_uucp()
  64. {
  65.     OSErr osErr;
  66.     osErr = _TCPInit();
  67.     if (osErr = noErr) {
  68.         osErr = _TCPCreate(&pb, &stream, streamBuf, streamBufLen, (TCPNotifyProc) asrProc, (Ptr) nil,  (TCPIOCompletionProc) nil, false);
  69.         if (noErr == osErr) {
  70.             osErr = TCPDotAddress(flds[FLD_PHONE], &remoteIP);
  71.             if (noErr == osErr) {
  72.                 osErr = _TCPActiveOpen(&pb, stream, remoteIP, remotePort, &localIP, &localPort, (Ptr) nil, (TCPIOCompletionProc) nil, false);
  73.             }
  74.         }
  75.     }
  76.     return osErr;
  77. }
  78.